home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 6.0 KB | 208 lines |
- ' ********************
- ' * Termites *
- ' * By Mike Richmond *
- ' ********************
- '
- ' Version 1.00
- '
- ' Termites is a semi-random movement generator. "How interesting!" I am sure
- ' you are saying to yourself, but if you run the program a few times, with
- ' different values for NUMBER (the number of termites in each base) and
- ' speed (the maximum speed the termites can dig at), it is actually quite
- ' fascinating.
- '
- ' You have all seen fractals - random but regular patterns created by complex
- ' mathematics. Well although termites is not quite as complex it is
- ' incredible how complex the patterns can become.
- '
- ' Programs like this one are used to research artificial intelligence at its
- ' most basic level. The termites in this program can dig up, down, left or
- ' right through the soil, at a speed of 0 to <SPEED> pixels. They start
- ' out from an invisible termite hill and spread out randomly, digging tunnels
- ' as they go (OK, OK, it should have been called earthworm...) Wherever a
- ' red termite goes, the soil goes red; wherever a blue one goes the soil turns
- ' blue. If they invade each others tunnels the part they travel on turns to
- ' their colour.
-
- '
- ' If you leave it for a long time (like an month:) you would eventually find
- ' that evrey pixel was covered by either a red or blue trail. And apparently,
- ' in the AI research labs, the termites actually seem to work together,
- ' creating ordered tunnels.
- '
- ' In this cut down version (there are no deaths, births, no eating or sleeping
- ' etc.), the termites can do 12 different things. They can move a random
- ' distance in one of 8 different directions (in practise this means they can
- ' move anywhere, as long as SPEED>1). They have a 1/12 chance of moving in
- ' any given direction. They have a 1/12 chance of carrying on in the same
- ' direction they were digging in last 'turn'. They also have a 2/12 chance of
- ' carrying on in almost the same direction they were last time, (a slight
- ' deviation), and a 1/12 chance of resting.
- '
- ' But even though it is all random, they seem to build a 'nest', and to send
- ' out lone termites to dig narrow passages of exploration. It's all good
- ' fun, really.
- '
- '
- ' Hold down the left mouse button to quit. Change the two variables below to
- ' alter the number of termites on each side and the maximum digging speed.
- '
- NUMBER=25 : SPEED=8
- '
- '
- '
- Hide On : Rem Get rid of the mouse pointer
- '
- Dim X1(NUMBER),Y1(NUMBER),X2(NUMBER),Y2(NUMBER),SX1(NUMBER),SY1(NUMBER)
- Dim SX2(NUMBER),SY2(NUMBER),OZ1(NUMBER),OZ2(NUMBER)
- ' Sort out arrays for X and Y positions of every termite , and the last
- ' direction they were diggin in
- '
- Randomize Timer : Rem Make sure the random numbers are always different
- '
- BLUEX=Rnd(318) : BLUEY=Rnd(198)
- REDX=Rnd(318) : REDY=Rnd(198)
- If BLUEX=<0 Then BLUEX=1 : If BLUEY<=0 Then BLUEY=0
- If REDX=<0 Then REDX=1 : If REDY<=0 Then REDY=0
- '
- ' Sort out random start positions for each base
- '
- For T=1 To NUMBER
- SX1(T)=REDX : SX2(T)=BLUEX
- SY1(T)=REDY : SY2(T)=BLUEY
- X1(T)=SX1(T) : Y1(T)=SY1(T)
- X2(T)=SX2(T) : Y2(T)=SY2(T)
- Next
- ' And put every termite in the base
- '
- Screen Open 0,320,200,4,Lowres
- Flash Off : Curs Off
- Palette $765,$F00,$F,$FFF : Cls 0
- '
- ' Sort out screen and palette
- '
- Repeat
- For T=1 To NUMBER
- X=Rnd(SPEED) : Y=Rnd(SPEED)
- ' Random X and Y digging speeds
- Z=Rnd(11)
- ' Random digging direction for this termite :
- ' 1 is up, 3 is right, etc.
- ' 0, 9 or 10 means carry on digging in the same or in a similar
- ' direction, giving them them a sort of goal. If 11 comes up then
- ' they have a rest
- If Z=0
- Z=OZ1(T)
- End If
- If Z=9
- Z=OZ1(T)+1
- If Z>7
- Z=1
- End If
- ' make sure they dig
- End If
- If Z=10
- Z=OZ1(T)-1
- If Z<0
- Z=7
- End If
- End If
- If Z=1
- Add Y1(T),-Y
- End If
- If Z=2
- Add X1(T),X : Add Y1(T),-Y
- End If
- If Z=3
- Add X1(T),X
- End If
- If Z=4
- Add X1(T),X : Add Y1(T),Y
- End If
- If Z=5
- Add Y1(T),Y
- End If
- If Z=6
- Add Y1(T),Y : Add X1(T),-X
- End If
- If Z=7
- Add X1(T),-X
- End If
- If Z=8
- Add X1(T),-X : Add Y1(T),-Y
- End If
- OZ1(T)=Z : Rem store the last digging direction
- '
- If X1(T)<0 Then X1(T)=0 : If X1(T)>319 Then X1(T)=319
- If Y1(T)<0 Then Y1(T)=0 : If Y1(T)>199 Then Y1(T)=199
- Ink 1 : Draw SX1(T),SY1(T) To X1(T),Y1(T)
- SX1(T)=X1(T) : SY1(T)=Y1(T)
- ' Make sure the termites are within the screen boundaries then
- ' store the old values, after drawing a line where it has been
- ' digging
- '
- ' And now the blue termites...
- '
- X=Rnd(SPEED) : Y=Rnd(SPEED)
- Z=Rnd(11)
- If Z=0
- Z=OZ2(T)
- End If
- If Z=9
- Z=OZ2(T)+1
- If Z>7
- Z=1
- End If
- End If
- If Z=10
- Z=OZ2(T)-1
- If Z<1
- Z=7
- End If
- End If
- If Z=1
- Add Y2(T),-Y
- End If
- If Z=2
- Add X2(T),X : Add Y2(T),-Y
- End If
- If Z=3
- Add X2(T),X
- End If
- If Z=4
- Add X2(T),X : Add Y2(T),Y
- End If
- If Z=5
- Add Y2(T),Y
- End If
- If Z=6
- Add Y2(T),Y : Add X2(T),-X
- End If
- If Z=7
- Add X2(T),-X
- End If
- If Z=8
- Add X2(T),-X : Add Y2(T),-Y
- End If
- OZ2(T)=Z
- '
- If X2(T)<0 Then X2(T)=0 : If X2(T)>319 Then X2(T)=319
- If Y2(T)<0 Then Y2(T)=0 : If Y2(T)>199 Then Y2(T)=199
- Ink 2 : Draw SX2(T),SY2(T) To X2(T),Y2(T)
- SX2(T)=X2(T) : SY2(T)=Y2(T)
- Next
- Until Mouse Key=1
- '
- Home : Cdown : Cdown : Cdown : Cdown : Cdown
- Pen 3 : Centre "Termites v1.00"
- Cdown : Cdown : Cdown : Cdown
- Centre "Another great program from..."
- Cdown : Cdown : Cdown : Cdown
- Centre "RipperSoft"
- Cdown : Cdown : Cdown : Cdown
- Centre "Press mouse to return to editor"
- Wait 25
- Repeat
- Until Mouse Key<>0
- Fade 2
- Edit